/** * Copyright (c) 2011-2014, OpenIoT * * This file is part of OpenIoT. * * OpenIoT is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * OpenIoT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenIoT. If not, see <http://www.gnu.org/licenses/>. * * Contact: OpenIoT mailto: info@openiot.eu * @author Timotee Maret */ package org.openiot.gsn.storage; import org.openiot.gsn.utils.jndi.GSNContext; import org.apache.commons.dbcp.BasicDataSource; import org.apache.log4j.Logger; import javax.naming.NamingException; public class DataSources { private static final transient Logger logger = Logger.getLogger( DataSources.class ); public static BasicDataSource getDataSource(DBConnectionInfo dci) { BasicDataSource ds = null; try { ds = (BasicDataSource)GSNContext.getMainContext().lookup(Integer.toString(dci.hashCode())); if (ds == null) { ds = new BasicDataSource(); ds.setDriverClassName(dci.getDriverClass()); ds.setUsername(dci.getUserName()); ds.setPassword(dci.getPassword()); ds.setUrl(dci.getUrl()); //ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); //ds.setAccessToUnderlyingConnectionAllowed(true); GSNContext.getMainContext().bind(Integer.toString(dci.hashCode()), ds); logger.warn("Created a DataSource to: " + ds.getUrl()); } } catch (NamingException e) { logger.error(e.getMessage(), e); } return ds; } }